#!/bin/sh



main(){

    jarFile=$1
    classes=$2
    javaFiles=$3

    cleanUp $classes $javaFiles
    unJar $jarFile $classes
    processFolder $classes $javaFiles
    Jar $javaFiles $jarFile
}

unJar(){

    target=$1
    output=$2
    if [ ! -d $output ]; then
        mkdir $output
    fi
    cd $output
    jar -xf $1
    cd ..
}

Jar(){

    sources=$1
    target=`basename $2 | sed -e 's/.jar/-13.sp1-sources.jar/g'`
    cd $sources; jar cvf $target ./
    mv -v $target ../ready/
    cd ..
}

processFolder() {

    classesFolder=$1
    outputFolder=$2

    find $classesFolder -type f | while read class; do
    echo $class;
    ./jad.exe -d $outputFolder -ff -f -lnc -o -pi32 -r -safe -space -stat -s java $class
    done
}

cleanUp(){
 rm -rf $1
 rm -rf $2
}


if [ $# -lt 3 ]; then
    echo 'Usage is decompileAll.sh targetJar classesFolder outputFolder'
else
    main $*
fi



